import { getAction, deleteAction, putAction, postAction, httpAction } from '@/api/manage'
import axios from 'axios'
import signMd5Utils from '@/utils/encryption/signMd5Utils'

// 仓库管理
const warehouseList = (params) => getAction('/wms/warehouse/list', params)
const warehouseListAll = (params) => getAction('/wms/warehouse/listAll', params)
const getWarehousesByIds = (params) => getAction('/wms/warehouse/getWarehousesByIds', params)
const warehouseSave = (params) => postAction('/wms/warehouse/add', params)
const warehouseEdit = (params) => putAction('/wms/warehouse/edit', params)
const warehouseDelete = (params) => deleteAction('/wms/warehouse/delete', params)
const warehouseDeleteBatch = (params) => deleteAction('/wms/warehouse/deleteBatch', params)
const warehouseExport = '/wms/warehouse/exportXls'
const warehouseImport = '/wms/warehouse/importExcel'

// 库位管理
const warehouseLocationList = (params) => getAction('/wms/location/list', params)
const warehouseLocationSave = (params) => postAction('/wms/location/add', params)
const warehouseLocationEdit = (params) => putAction('/wms/location/edit', params)
const warehouseLocationDelete = (params) => deleteAction('/wms/location/delete', params)
const warehouseLocationDeleteBatch = (params) => deleteAction('/wms/location/deleteBatch', params)
const warehouseLocationExport = '/wms/location/exportXls'
const warehouseLocationGenerateQrcode = (params) => getAction('/wms/location/generateQrcode', params)
const warehouseLocationBatchGenerateQrcode = (params) => getAction('/wms/location/batchGenerateQrcode', params)
const warehouseLocationBatchGenerate = (params) => postAction('/wms/location/batchGenerate', params)
const warehouseLocationListByWarehouseId = (params) => getAction('/wms/location/queryByWarehouseId', params)

// 商品管理
const productList = (params) => getAction('/wms/product/list', params)
const productSave = (params) => postAction('/wms/product/add', params)
const productEdit = (params) => putAction('/wms/product/edit', params)
const productDelete = (params) => deleteAction('/wms/product/delete', params)
const productDeleteBatch = (params) => deleteAction('/wms/product/deleteBatch', params)
const productExport = '/wms/product/exportXls'
const productListAll = (params) => getAction('/wms/product/listAll', params)

// 物料管理
const materialList = (params) => getAction('/wms/material/list', params)

const materialAdd = (params) => postAction('/wms/material/add', params)

const materialEdit = (params) => putAction('/wms/material/edit', params)

const materialDelete = (id) => deleteAction('/wms/material/delete', { id })

const materialDeleteBatch = (ids) => deleteAction('/wms/material/deleteBatch', { ids })

const materialExport = '/wms/material/exportXls'

const materialImport = '/wms/material/importExcel'

const materialListAll = (params) => getAction('/wms/material/listAll', params)
const materialListByType = (params) => getAction('/wms/material/listByType', params)
const materialQueryByCode = (materialCode) => getAction('/wms/material/queryByCode', { materialCode })

// 半料管理明细
const materialDetailSave = (materialId, details) => postAction('/wms/material/detail/save', {
  materialId,
  details
})

const materialDetailList = (materialId) => getAction('/wms/material/detail/list', { materialId })

// 库存管理
const inventoryList = (params) => getAction('/wms/inventory/list', params)

const inventoryEdit = (params) => putAction('/wms/inventory/edit', params)

const inventoryInbound = (inventory, params) => {
  return postAction('/wms/inventory/inbound', params, { inventory: inventory })
}

const inventoryOutbound = (inventory, params) => {
  return postAction('/wms/inventory/outbound', params, { inventory: inventory })
}

const inventoryAdjust = (adjustVO) => {
  return postAction('/wms/inventory/adjust', adjustVO)
}

const inventoryMove = (moveVO) => {
  return postAction('/wms/inventory/move', moveVO)
}

const inventoryInboundWithCost = (inventoryVO) => {
  return postAction('/wms/inventory/inboundWithCost', inventoryVO)
}

// 创建入库单
const createInboundOrder = (inboundOrder) => {
  console.log('创建入库单API请求参数:', JSON.stringify(inboundOrder));
  console.log('业务单号检查:', inboundOrder.businessNo);
  return postAction('/wms/inboundOrder/add', inboundOrder)
}

// 编辑入库单
const editInboundOrder = (inboundOrder) => {
  return putAction('/wms/inboundOrder/edit', inboundOrder)
}

// 添加余料入库单
const createSurplusInboundOrder = (inboundOrder) => {
  return postAction('/wms/inboundOrder/addSurplus', inboundOrder)
}

// 确认入库
const confirmInbound = (params) => {
  return postAction('/wms/inboundOrder/confirmInbound', params)
}

// 取消入库单
const cancelInboundOrder = (params) => {
  return postAction('/wms/inboundOrder/cancelInboundOrder', params)
}

const inventoryOutboundWithCost = (inventory, params) => {
  return postAction('/wms/inventory/outboundWithCost', params, { inventory: inventory })
}

const inventoryAdjustCost = (inventory, params) => {
  return postAction('/wms/inventory/adjustCost', params, { inventory: inventory })
}

const inventoryTransfer = (params) => postAction('/wms/inventory/transfer', params)
const inventoryCheck = (params) => postAction('/wms/inventory/check', params)
const inventoryFreeze = (params) => postAction('/wms/inventory/freeze', params)
const inventoryUnfreeze = (params) => postAction('/wms/inventory/unfreeze', params)
const inventoryScrap = (params) => postAction('/wms/inventory/scrap', params)
const inventoryHistoryList = (params) => getAction('/wms/inventory/history/list', params)
const inventoryExport = '/wms/inventory/exportXls'

// 领料管理
const requisitionList = (params) => getAction('/wms/requisition/list', params)
const requisitionSave = (params) => postAction('/wms/requisition/add', params)
const requisitionEdit = (params) => putAction('/wms/requisition/edit', params)
const requisitionDelete = (params) => deleteAction('/wms/requisition/delete', params)
const requisitionSubmit = (params) => postAction('/wms/requisition/submit', params)
const requisitionApprove = (params) => postAction('/wms/requisition/approve', params)
const requisitionReject = (params) => postAction('/wms/requisition/reject', params)
const requisitionCancel = (params) => postAction('/wms/requisition/cancel', params)
const requisitionExecute = (params) => postAction('/wms/requisition/execute', params)
const requisitionDetail = (params) => getAction('/wms/requisition/queryById', params)
const requisitionExport = '/wms/requisition/exportXls'
const requisitionPrint = (params) => getAction('/wms/requisition/print', params)

// 领料单附件相关接口
const requisitionAttachmentList = (params) => getAction('/wms/requisition/attachment/list', params)
const requisitionAttachmentDelete = (params) => deleteAction('/wms/requisition/attachment/delete', params)
const requisitionAttachmentUpload = (params) => postAction('/wms/requisition/attachment/upload', params)

export {
  // 仓库管理
  warehouseList,
  warehouseListAll,
  getWarehousesByIds,
  warehouseSave,
  warehouseEdit,
  warehouseDelete,
  warehouseDeleteBatch,
  warehouseExport,
  warehouseImport,
  
  // 库位管理
  warehouseLocationList,
  warehouseLocationSave,
  warehouseLocationEdit,
  warehouseLocationDelete,
  warehouseLocationDeleteBatch,
  warehouseLocationExport,
  warehouseLocationGenerateQrcode,
  warehouseLocationBatchGenerateQrcode,
  warehouseLocationBatchGenerate,
  warehouseLocationListByWarehouseId,
  
  // 商品管理
  productList,
  productSave,
  productEdit,
  productDelete,
  productDeleteBatch,
  productExport,
  productListAll,
  
  // 物料管理
  materialList,
  materialAdd,
  materialEdit,
  materialDelete,
  materialDeleteBatch,
  materialExport,
  materialImport,
  materialListAll,
  materialListByType,
  materialDetailSave,
  materialDetailList,
  materialQueryByCode,
  
  // 库存管理
  inventoryList,
  inventoryEdit,
  inventoryInbound,
  inventoryOutbound,
  inventoryAdjust,
  inventoryMove,
  inventoryInboundWithCost,
  inventoryOutboundWithCost,
  inventoryAdjustCost,
  inventoryTransfer,
  inventoryCheck,
  inventoryFreeze,
  inventoryUnfreeze,
  inventoryScrap,
  inventoryHistoryList,
  inventoryExport,
  createInboundOrder,
  editInboundOrder,
  createSurplusInboundOrder,
  confirmInbound,
  cancelInboundOrder,
  
  // 领料管理
  requisitionList,
  requisitionSave,
  requisitionEdit,
  requisitionDelete,
  requisitionSubmit,
  requisitionApprove,
  requisitionReject,
  requisitionCancel,
  requisitionExecute,
  requisitionDetail,
  requisitionExport,
  requisitionPrint,
  requisitionAttachmentList,
  requisitionAttachmentDelete,
  requisitionAttachmentUpload
} 